﻿using System;
using System.Drawing;
using System.Linq;
using System.Text;
using SkaldRogueLike.Main.Constants;
using SkaldRogueLike.Main.Constants.Enumerations;
using SkaldRogueLike.Main.DungeonGenerating;

namespace SkaldRogueLike.Main
{
    class Program
    {
        //private static Game1 _game1;
        private static string _text;

        static void Main(string[] args)
        {
            var map = DungeonGenerator.CreateFinalMap(25, 19, 50, 50, 50, new RoomGenerator(4, 6, 2, 4, 5));
            var drawIt = MapConverter.ConvertDungeonToTiles(map);
            Console.OutputEncoding = Encoding.UTF8;
            Console.Clear();
            for (var i = 0; i < drawIt.GetLength(0); i++)
            {
                for (var j = 0; j < drawIt.GetLength(1); j++)
                {
                    Console.Write((char)drawIt[i, j]);
                }
                Console.WriteLine();
            }

            //_game1 = new Game1();
            //_game1.GenerateStartInventoryForCharacter();
            //_game1.GenerateCreatures();
            //_game1.GenerateItems();
            //_game1.UpdateMap();
            //while (!_game1.End)
            //{
            //    DrawMap(_game1);
            //    Console.WriteLine(_text);
            //    _text = MoveChar(Console.ReadKey(true));
            //    _text += _game1.Update();
            //}
            //Console.WriteLine(Messages.Die);
        }
        /*
        private static string MoveChar(ConsoleKeyInfo command)
        {
            var stringBuilder = new StringBuilder();
            ConsoleKeyInfo key;
            switch (command.Key)
            {
                #region move
                case ConsoleKey.UpArrow:
                case ConsoleKey.NumPad8:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.North));
                    break;
                case ConsoleKey.DownArrow:
                case ConsoleKey.NumPad2:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.South));
                    break;
                case ConsoleKey.LeftArrow:
                case ConsoleKey.NumPad4:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.West));
                    break;
                case ConsoleKey.RightArrow:
                case ConsoleKey.NumPad6:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.East));
                    break;
                case ConsoleKey.NumPad7:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.NorthWest));
                    break;
                case ConsoleKey.NumPad9:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.NorthEast));
                    break;
                case ConsoleKey.NumPad1:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.SouthWest));
                    break;
                case ConsoleKey.NumPad3:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.SouthEast));
                    break;
                case ConsoleKey.NumPad5:
                    stringBuilder.Append(_game1.MoveCharacter(Direction.None));
                    break;
                #endregion
                // commands with choices
                case ConsoleKey.I:
                    Console.WriteLine(Messages.HavePattern, _game1.ShowInventory());
                    Console.WriteLine(Messages.PressToPattern, "w", "equip");
                    Console.WriteLine(Messages.PressToPattern, "d", "drop");
                    key = Console.ReadKey(true);
                    if (IsEscOrNonLetterKey(key.Key))
                        break;
                    if (key.Key == ConsoleKey.W)
                        goto case ConsoleKey.W;
                    if (key.Key == ConsoleKey.D)
                        goto case ConsoleKey.D;
                    //todo
                    //stringBuilder.AppendFormat(Messages.PressToPattern, "letter", "use");
                    break;
                case ConsoleKey.W:
                    Console.WriteLine(Messages.HavePattern + Messages.MakeYourChoice, 
                        _game1.ShowEquipmentFromBag());
                    key = Console.ReadKey(true);
                    if (IsEscOrNonLetterKey(key.Key))
                        break;
                    stringBuilder.Append(_game1.Equip(key.KeyChar));
                    break;
                case ConsoleKey.D:
                    Console.WriteLine(Messages.HavePattern + Messages.MakeYourChoice, 
                        _game1.ShowEquipmentFromBag());
                    key = Console.ReadKey(true);
                    if (IsEscOrNonLetterKey(key.Key))
                        break;
                    stringBuilder.Append(_game1.Drop(key.KeyChar));
                    break;
                case ConsoleKey.E:
                    Console.WriteLine(Messages.WearPattern, _game1.ShowEquipped());
                    Console.WriteLine(Messages.PressToPattern, "letter", "equip/unequip");
                    key = Console.ReadKey(true);
                    if (IsEscOrNonLetterKey(key.Key))
                        break;
                    stringBuilder.Append(_game1.Unequip(key.KeyChar));
                    break;
                case ConsoleKey.Spacebar:
                    var items = _game1.ShowCurrentCellItems();
                    if (!items.Contains("b) "))
                    {
                        stringBuilder.Append(_game1.PickUp('a'));
                        break;
                    }
                    Console.WriteLine(Messages.SeePattern + Messages.MakeYourChoice, items);
                    Console.WriteLine(Messages.PressToPattern, "letter", "pick up");
                    key = Console.ReadKey(true);
                    if (IsEscOrNonLetterKey(key.Key))
                        break;
                    stringBuilder.Append(_game1.PickUp('*'));
                    break;
                #region general
                case ConsoleKey.F1:
                    stringBuilder.Append(_game1.GetHelp());
                    break;
                case ConsoleKey.Q:
                    Console.WriteLine(Messages.Quit);
                    if (Console.ReadKey(true).Key == ConsoleKey.Y)
                        Environment.Exit(0);
                    break;
                #endregion
            }
            return stringBuilder.ToString();
        }

        private static bool IsEscOrNonLetterKey(ConsoleKey key)
        {
            return key == ConsoleKey.Escape || (key != ConsoleKey.Multiply && (key < ConsoleKey.A || key > ConsoleKey.Z));
        }

        private static void DrawMap(Game1 game1)
        {
            Console.Clear();
            for (var i = 0; i < game1.Map.GetLength(1); i++)
            {
                for (var j = 0; j < game1.Map.GetLength(0); j++)
                {
                    Console.ForegroundColor = SetColor(game1.Map[j, i].Color);
                    Console.Write(game1.Map[j, i].Image);
                }
                Console.WriteLine();
            }
        }*/
    }
}
